<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--引入JSTL标签--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no,initial-scale=1.0 maximum-scale=1.0,minimum-scale=1.0">
    <title>购物车</title>
    <%
        String basePathh = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
    %>
    <base href="<%=basePathh%>">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/cart.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1728297_0ggrtwuzmzib.css">
    <link rel="script" href="http://res.wx.qq.com/open/js/jweixin-1.6.0.js">
    <script src="js/flexible.js"></script>
    <script src="static/script/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        $(function () {
            $("button#jian").click(function () {
                var id = $(this).attr('bookid');
                var count = $(this).parent().find("input:first").val();
                location.href = "cartServlet?action=jian&count=" + count + "&id=" + id;
            });
            $("button#jia").click(function () {
                var id = $(this).attr('bookid');
                var count = $(this).parent().find("input:first").val();
                location.href = "cartServlet?action=jia&count=" + count + "&id=" + id;
            });
            $("a.del").click(function () {
                return confirm("您确定要删除【" + $(this).parent().parent().find("div:first").text() + "】吗？");
            });
            $("a.clearr").click(function () {
                return confirm("您确定要清空购物车吗？");
            });
            $("input.cnt").change(function () {
                var name = $(this).parent().parent().find("div:first").text();
                var id = $(this).attr('bookid');
                var count = this.value;
                if (confirm("您确定要将【" + name + "】的数量修改为" + count + "吗？")) {
                    location.href = "cartServlet?action=updatecnt&count=" + count + "&id=" + id;
                } else {
                    this.value = this.defaultValue;
                }
            });

            $("#zhuzhifu").attr("href", "alipays://platformapi/startapp?appId=09999988&actionType=toAccount&goBack=NO&amount=" + "${sessionScope.cart.totalPrice}" + "&userId=2088432071209725&memo=请确认转账名字是否为*洪欣");
        });
    </script>


</head>

<body>

<div class="nav">
    <div class="gogogo iconfont icon-cart"><a class="clearr" href="cartServlet?action=clearcart">清空购物车</a></div>


</div>

<div class="main">
    <c:if test="${empty sessionScope.cart.items}">
        <tr>
            <td colspan="5"><a href="foodServlet?action=page">亲，当前购物车为空！快去浏览商品吧(点击可以跳到首页)</a>
        </tr>
    </c:if>
    <c:if test="${not empty sessionScope.cart.items}">
        <c:forEach items="${sessionScope.cart.items}" var="entry">
            <div class="shop1">
                <img src="${entry.value.imgpath}" alt="">
                <div class="name">${entry.value.name}</div>
                <div class="price">￥${entry.value.price}</div>
                <div id="singlezongjia" class="pricez">总价￥${entry.value.totalPrice}</div>
                <div class="anniu">
                    <button id="jian" bookid="${entry.value.id}"
                            class="iconfont icon-wuuiconsuoxiao"></button>
                    <input id="cnt" class="cnt" type="text" bookid="${entry.value.id}" value="${entry.value.count}">
                    <button id="jia" bookid="${entry.value.id}"
                            class="iconfont icon-shuliangtianjia-"></button>
                    <a class="del iconfont icon-quanbushanchu"
                       href="cartServlet?action=deleteItem&id=${entry.value.id}"></a>
                </div>
            </div>

        </c:forEach>
    </c:if>
</div>
<div class="dibu">
    <div class="all">
        <i class="iconfont icon-yiban"><span id="zongjia"> 合计:￥${sessionScope.cart.totalPrice}</span></i>
    </div>
    <div class="pay">
        <a id="zhuzhifu" href="" class="iconfont icon-zhifubaozhifu">去支付</a>
    </div>
    <div class="pay">
        <a href="cartServlet?action=vxpay" class="iconfont icon-weixin">去支付</a>
    </div>
    <div class="pay">
        <a href="alipayqr://platformapi/startapp?saId=10000007&qrcode=https://qr.alipay.com/fkx09752i6eqlskkoqcxy2e"
           class="iconfont icon-zhifubaozhifu">支付(备用)</a>
    </div>

</div>


</body>

</html>